<?php
namespace app\tools\middleware;
use app\tools\logic\ApiLogic;
use think\Facade\Db;
/**
 * @author KEL
 * @登录验证 
 * @Date   2020-07-09 17:34:42
 * @Author  <1067547248@qq.com>
 */
class LoginCheck{
	public function handle($request, \Closure $next){
		$token = $request->header('token');
		if(!$token){
			return ApiLogic::return(300);
		}
		//查询账户信息
		$info = Db::name('auth_user')
					->field('id,token,token_exp,status')
					->where('token',$token)
					->find();
		if(!$info){
			return ApiLogic::return(301);
		}
		if($info['status']!=1){
			return ApiLogic::return(107);
		}
		if($info['token_exp']<=date('Y-m-d H:i:s')){
			return ApiLogic::return(302);
		}
		
		return $next($request);
    }

    public function end(\think\Response $response){
        // 回调行为
        // return $response;
    }
}